package veterinaria.servlet.atencionmedica;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.AtencionMedica;
import veterinaria.modelo.Cita;
import veterinaria.negocio.GestionAtencionMedica;
import veterinaria.negocio.GestionCita;

/**
 * Servlet implementation class AtencionMedicaEditar
 */
@WebServlet("/AtencionMedicaEditar")
public class AtencionMedicaEditarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AtencionMedicaEditarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int a = Integer.parseInt(request.getParameter("id"));
		GestionAtencionMedica negocio = new GestionAtencionMedica();
		try {			
			AtencionMedica am = negocio.obtener(a);
			request.setAttribute("am", am);
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		RequestDispatcher rd = request.getRequestDispatcher("atencionMedicaEditar.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		GestionAtencionMedica am = new GestionAtencionMedica();
		//int idDoc = Integer.parseInt(request.getParameter("idDoctor"));
		//int idPac = Integer.parseInt(request.getParameter("idPaciente"));
		int idAtencionMedica = Integer.parseInt(request.getParameter("idAtencionMedica"));
		try {
		 am.actualizar(
				request.getParameter("dsNotasMedicas"), request.getParameter("dsImagenes"),
				request.getParameter("dsCondEspec"), idAtencionMedica,  "1"
			);
				
		} catch (DAOExcepcion e) {
			// TODO: handle exception
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		response.sendRedirect(request.getContextPath() + "/atencionMedica.jsp");
	}

}
